<template>
	<view>
		<image :src="url" mode="scaleToFill" @error="imageError" @longtap="longtap" :style="{height:height + 'px',width:100 + '%'}"></image>
		<view class="jump-over" @tap="launchFlag">跳过  {{Count}}</view>
	</view>
</template>

<script>
	import utils from '@/static/js/utils.filter.js';
	var time = null
	export default {
		data() {
			return {
				height: this.screenHeight,
				Count:3,
				url: ''
			}
		},
		onLoad() {
			time = setInterval(() => {
				if(this.Count == 1) {
					clearInterval(time)
					uni.reLaunch({
						url: '/pages/home/home'
					});
				} else {
					this.Count = this.Count - 1
				}
			},1000)
			let guideurl = 'https://www.ahlinghui.com/Uploads/image/mryq/' + utils.timeTodate('Ymd', new Date().getTime()) +
				'.png';
			this.url = guideurl
			uni.setStorage({
				key: 'guide',
				data: guideurl
			})
		},
		methods: {
			//长按图片保存
			longtap() {
				console.log('触发长按事件');
				uni.downloadFile({
					url: this.url,
					success: (res) => {
						if (res.statusCode === 200) {
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath,
								success: function() {
									uni.showToast({
										title: "保存成功",
										icon: "none"
									});
								},
								fail: function() {
									uni.showToast({
										title: "保存失败，请稍后重试",
										icon: "none"
									});
								}
							});
						}
					}
				})
			},
			launchFlag() {
				// if(this.Count == '跳过') {
					clearInterval(time)
					uni.reLaunch({
						url: '/pages/home/home'
					});
				// }
			},
			imageError(e) {
				if (e.detail.errMsg.indexOf('404') != -1) {
					this.url = 'https://www.ahlinghui.com/Uploads/image/mryq/limesoft.png'
					uni.setStorage({
						key: 'guide',
						data: 'https://www.ahlinghui.com/Uploads/image/mryq/limesoft.png'
					})
				}
			}
		}
	}
</script>

<style>
	.jump-over {
		position: absolute;
		width: 130rpx;
		height: 70rpx;
		line-height: 70rpx;
		/* padding: 0 68rpx; */
		border-radius: 50rpx;
		font-size: 30rpx;
		text-align: center;
		color: #FFFFFF;
		background-color: rgba(128,139,161,0.8);
		/* border: 1px solid #77a9fb; */
		z-index: 999;
		right: 30rpx;
		bottom: 73rpx;
	}
</style>
